package  
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	/**
	 * ...
	 * @author patsup
	 */
	public class GenButton extends Button 
	{
		private var inputFunc:Function;							//function to call on mouseclick
		public var mc:MovieClip;
		
		private var btnLabel:TextField;							//button label
		private var txtFormat:TextFormat;
		
		public function GenButton(xCoord:int, yCoord:int, movieClipClass:Class, inputFunc:Function, txt:String = null, txtFormat:TextFormat = null, txtXCoord:int = 0, txtYCoord:int = 0)
		{
			name = (txt?"txt":"Generic") + " Button";
			this.inputFunc = inputFunc;
			btnLabel = new TextField();
			mc = new movieClipClass();
			addChild(mc);
			
			//if(txt) btnLabel.text = txt;
			if (txtFormat == null) {				//default text format settings
				this.txtFormat = new TextFormat();
				this.txtFormat.size = 35;
				this.txtFormat.font = "Arial";
				this.txtFormat.color = 0x804000;
				//this.txtFormat.align = TextFormatAlign.CENTER;	//but what about center-aligning y with height?
			} else {
				this.txtFormat = txtFormat;
			}
			
			if (txt) SetButtonLabel(txt, txtXCoord, txtYCoord);
			
			addChild(btnLabel);									//now add this txt label to the display list
			
			InitImage();
			InitInput();
			
			super(xCoord, yCoord);
		}
		
		//SetButtonLabel
		//if the x and y coord are 0, then default to centering the text
		//(so if u want it in the upper left corner make it something stupid like (1,1) or something)
		public function SetButtonLabel(label:String, txtXCoord:int = 0, txtYCoord:int = 0):void
		{
			btnLabel.text = label;									//set the text
			btnLabel.setTextFormat(txtFormat);						//set the format
			if (txtXCoord == 0) {
				btnLabel.x = 0.5 * width - 0.5 * btnLabel.textWidth;	//default to centering text
			} else {
				btnLabel.x = txtXCoord;
			}
			if (txtYCoord == 0) {
				btnLabel.y = 0.5 * height - 0.5 * btnLabel.textHeight;	//default to centering text
			} else {
				btnLabel.y = txtYCoord;
			}
			//trace("btnlw=" + btnLabel.width);
			btnLabel.width = width - btnLabel.x;					//make sure it doesn't hang off the button
			//trace("btnlw=" + width + label);
			btnLabel.height = height - btnLabel.y;
		}
		
		//InitImage()
		//Initializes the image of the Button
		protected override function InitImage():void
		{
			super.InitImage();
		}
		
		//InputMouseClick()
		//Takes action for Button upon hearing the mouseclick event
		protected override function InputMouseClick(e:MouseEvent):void
		{
			inputFunc();
			super.InputMouseClick(e);
		}
		
		//ChangeIMCFunc()
		//Change the InputMouseClick Function
		public function ChangeIMCFunc(inputFunc:Function):void
		{
			this.inputFunc = inputFunc;
		}
		
	}

}